<?
    class Principio_Controller_Plugin extends Zend_Controller_Plugin_Abstract
    {
        private function dispatchAuth(Zend_Controller_Request_Abstract $request_abstract)
        {
            if (Zend_Auth::getInstance()->hasIdentity())
            {
                Zend_Layout::getMvcInstance()->setLayout("auth");
                $request_abstract->setControllerName("faxes")->setActionName("index");
            }
            else
                $request_abstract->setActionName("index");
        }


        public function preDispatch(Zend_Controller_Request_Abstract $request_abstract)
        {
             switch ($request_abstract->getControllerName())
             {
                case "index":
                    if (!Zend_Auth::getInstance()->hasIdentity())
                    {
                        if (!is_null($request_abstract->getParam("sign-in")))
                        {
                            Zend_Auth::getInstance()->authenticate(new FaxCenter_Auth(
                                $request_abstract->getParam("email"),
                                $request_abstract->getParam("password")
                            ));
                        };
                    }
                    else
                    {
                        if (!is_null($request_abstract->getParam("logout")))
                            Zend_Auth::getInstance()->clearIdentity();
                    };

                    $this->dispatchAuth($request_abstract);

                    break;

                default:
                    break;
            }
        }
    }
?>